<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/11/12
 * Time: 17:47
 */

namespace app\index\controller;


use think\Db;

class Zhengce extends Base
{
    /**
     * 习近平讲话列表展示
     * @return mixed
     */
    public function zcList(){
        $page = input('page')?input('page'):1;
        $zc_type = input('zc_type');
        $list = Db::table('up_zhengce')
            ->where('zc_type', $zc_type)
            ->order('zc_time desc')
            ->page($page, 12)
            ->select();
        foreach($list as $k => $v){
            if($v['zc_num'] >= 1000){
                $list[$k]['zc_num'] = number_format($v['zc_num']/1000, 1) . 'k';
            }
        }
        $this->assign('list', $list);
        $this->assign('zc_type', $zc_type);
        return $this->fetch('zhengce/zclist');
    }
    
    /**
     * 更多政策解读---按钮显示
     * @return \think\response\Json
     */
    public function showMore(){
        $zc_type = input('zc_type');
        $count = Db::table('up_zhengce')->where('zc_type', $zc_type)->count();
        return json(['status' => 200, 'count' => $count]);
    }
    
    /**
     * 更多政策解读
     * @return \think\response\Json
     */
    public function moreZc(){
        $page = input('page');
        $zc_type = input('zc_type');
        $keyword = input('keyword');
        $where = array();
        $where['zc_type'] = $zc_type;
        if($keyword != ''){
            $where['zc_title'] = ['like','%'.$keyword.'%'];
        }
        $data = Db::table('up_zhengce')
            ->where($where)
            ->order('zc_time desc')
            ->limit(($page-1)*12, 12)
            ->select();
        foreach($data as $k => $v){
            if($v['zc_num'] >= 1000){
                $data[$k]['zc_num'] = number_format($v['zc_num']/1000, 1) . 'k';
            }
        }
        return json(['status' => 200, 'data' => $data]);
    }
}